<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<body>
    <script>
        // 递归
        // 1.求n的阶乘 n! 10 * 9 * 8 * ...* 1
    	function f1(n){
    		if(n==0){
    			return 1
    		}else{
    			return n * f1(n-1)
    		}
    	}

        // 2.斐波那契数列:从第三项开始,后面的每一项都是前两项的和,其中第一项和第二项都是1,写出是 1, 1, 2, 3, 5, 8, 13, 21, 34, 55,....,求第n项的值
        function f2(){
        	if(n < 3){
        		return 1
        	}else{
        		return f2(n-1) + f(n-2)
        	}
        }
        // 3.一元钱可以买一瓶水,两个空瓶可以换一瓶水,三个瓶盖可以换一瓶水,20块钱换几瓶
      
      	//1 1
      	//2 5 
      	//3 11
      	function f3(){
      		if(n = 1){
      			return 1
      		}else if(n === 2){
      			return 5
      		}else{
      			return f3(n - 1)+6
      		}

      	}

        // // 写出变量提升的过程
        // 1.
        console.log(a)
		function a(){
			console.log("aaa")
		}
		var a = 1;
		console.log(a)

		//
		function a(){
			console.log("aaa")
		}
		var a
		console.log(a)
 		a = 1
 		console.log(a)
        // 2.
		var foo = function(x, y){
			return x + y;
		}
		function foo(x, y){
			return x - y;
		}
		var num = foo(1, 2)
		console.log(num)

		//
		function foo(x, y){
			return x - y;
		}	
		var foo
		var num
		foo = function(x, y){
			return x + y;
		}
		num = foo(1, 2)
		console.log(num)
        // 3
		console.log(a)
		var a = 1;
		console.log(a)
		function a(){
			console.log(2)
		}
		console.log(a)
		var a = 3;
		console.log(a)
		function a(){
			console.log(4)
		}
		console.log(a)
		a()
		//
		function a(){
			console.log(2)
		}
		function a(){
			console.log(4)
		}
		var a
		var a
		console.log(a)
		a = 1
		console.log(a)
		console.log(a)
		a = 3
		console.log(a)
		console.log(a)
		a()
        // 预习数组  数组的取值， 数组的遍历， 数组的冒泡排序
        // 预习完成下面作业
        // 1.求下面数组的平均值
        var arr1 = [1, 6, 7, 20, 30]
        let sum = 0
        for(let i = 0; i < arr1.length;i++){
        	sum = sum+arr1[i]
        }
        let avg = sum / arr1.length
        console.log(avg)

        // 2.找出数组最大值
		var arr2 = [3, 4, 6, 11, 35, 20, 16]
		var max =arr2[0]
		for(let i = 0; i < arr2.length; i++){
			if(max < arr[i]){
				max = arr[i]
			}
		}
		console.log(max)
    </script>
</body>
</html>